#include "DirectLOL/gameEngine/inputeventmanager.h"

InputEventManager::InputEventManager()
{
    mousePositionX=0;
    mousePositionY=0;
    event = new SDL_Event();
    spaceDown=0;
    leftMouseDown=0;
    rightMouseDown=0;
}

void InputEventManager::DeStackEvents()
{
    keyboardState=SDL_GetKeyState(NULL);

    //  SDL_WaitEvent(&event);	        //	Méthode qui attends qu'un événement se produise, blocante
    while(SDL_PollEvent(event))        //	Méthode qui se déclenche lors qu'un événement se produit, non blocante
    {
        if(event->type==SDL_KEYDOWN)
        {
            keyDown[event->key.keysym.sym]=1;
            if(event->key.keysym.sym==SDLK_ESCAPE)
            {
                SDL_Quit();
            }
            else if(event->key.keysym.sym==SDLK_SPACE)
            {
                spaceDown=1;
            }
        }
        else if (event->type==SDL_KEYUP)
        {
            keyUp[event->key.keysym.sym-97]=1;
        }
        else if(event->type==SDL_MOUSEMOTION)
        {
            mousePositionX=event->motion.x;
            mousePositionY=event->motion.y;

            mouseMoved=1;
        }
        else if(event->type==SDL_MOUSEBUTTONDOWN)
        {
            if(event->button.button==SDL_BUTTON_LEFT)
            {
                leftMouseDown=1;
            }
            else if(event->button.button==SDL_BUTTON_RIGHT)
            {
                rightMouseDown=1;
            }
        }
    }
}


int InputEventManager::KeyDown(int code)
{
    return keyDown[code];
}

int InputEventManager::KeyUp(int code)
{
    return keyUp[code];
}

int InputEventManager::KeyPressed(int code)
{
    return keyboardState[code];
}

int InputEventManager::MouseMoved()
{
    return mouseMoved;
}

int InputEventManager::RightMouseDown()
{
    return rightMouseDown;
}

int InputEventManager::LeftMouseDown()
{
    return leftMouseDown;
}

void InputEventManager::ResetKeyState()
{
    for(int i=0; i<500;i++)
    {
        keyDown[i]=0;
        keyUp[i]=0;
    }

    mouseMoved=0;
    spaceDown=0;
    leftMouseDown=0;
    rightMouseDown=0;
}
